package com.example.mqdemo.PointToPoint.normalType;

import com.example.mqdemo.util.ConnectionUtil;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

/*
 *@description: 点对点队列消息发送者普通版
 *@author: hisen
 *@Time: 2023/11/20  20:57
 */
public class PointToPointProducer {
private static final String QUEUE_NAME = "point_to_point";
    public static void main(String[] args) throws Exception {
        //获取mq连接
        Connection connection = ConnectionUtil.getConnection();
        //创建mq通道
        Channel channel = connection.createChannel();
        //创建队列
        channel.queueDeclare(QUEUE_NAME,false,false,false,null);
        //发送消息
        String msg="Hello RabbitMQ!";
        channel.basicPublish("",QUEUE_NAME,null,msg.getBytes());
        System.out.println("发送消息："+msg+" 成功！");
        //关闭通道
        channel.close();
        //关闭mq连接
        connection.close();
    }
}
